package com.yamaikj.controller;

import com.yamaikj.config.DataSource;
import com.yamaikj.config.DataSourceType;
import com.yamaikj.config.DynamicDataSourceContextHolder;
import com.yamaikj.model.User;
import com.yamaikj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cloud.context.config.annotation.RefreshScope;
//import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/user")
//@RefreshScope
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/save")
    @ResponseBody
    public String save(){
        User user = new User();
        user.setName("测试1");
        userService.save(user);
        return "ok";
    }

    @RequestMapping(value = "/find")
    @ResponseBody
    public User find(Long id){
        User user = new User();
        user.setName("测试1");
        userService.save(user);
        user = userService.findUserByIdForUpdate(2L);
        return user;
    }

//    @Value("${ev}")
//    private String ev;
//
//    @RequestMapping(value = "/sys")
//    @ResponseBody
//    @PreAuthorize("hasRole('ROLE_ADMIN')")
//    public String sys(){
//        System.out.println("sys");
//        System.out.println(ev);
//        return "ok";
//    }
//
//    @RequestMapping(value = "/find")
//    @ResponseBody
//    @PreAuthorize("hasRole('ROLE_ADMIN')")
//    public User find(Long id){
//        return userService.findUserById(1L);
//    }

}
